package com.TT.controller;

import com.TT.common.REST.RESTResponse;
import com.TT.common.REST.ResCode;
import com.TT.domain.mysql.User;
import com.TT.service.mysql.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 苏文广 on 2018/11/22
 */
@Controller
@RequestMapping("/view")
public class ViewController {
    @Autowired
    UserService userService;
    @RequestMapping("/freemarker")
    public String freemarker(Model model) {
        String word0 = "Hello ";
        String word1 = "World!";
        //將數據添加到視圖數據容器中
        model.addAttribute("word0",word0);
        model.addAttribute("word1",word1);
        return "helloWorld.ftl";
    }

    /**
     * 返回主页
     * @return 主页
     */
    @RequestMapping("/index")
    public String index(){
        return "index.ftl";
    }

    /**
     * 返回用户列表视图
     *
     * @return 返回用户列表
     */
    @RequestMapping("/user/list")
    public String user_list(){
        return "user/user_list.ftl";
    }

    /**
     * 添加用户视图
     *
     * @return 添加视图
     */
    @RequestMapping("/user/add")
    public String user_add() {
        return "user/user_add.ftl";
    }

    /**
     * 查询个人信息视图
     *
     * @param id    userId
     * @param model user
     *
     * @return 查询
     */
    @RequestMapping("/user/query/{id}")
    public String user_query(@PathVariable int id, Model model) {
        User user = userService.getUserInfo(id);
        model.addAttribute(user);
        return "user/user_query.ftl";
    }

    @RequestMapping("/user/edit/{id}")
    public String user_edit(@PathVariable int id, Model model) {
        User user = userService.getUserInfo(id);
        model.addAttribute(user);
        return "user/user_edit.ftl";
    }




}
